/*
 *    Copyright (c) 2018-2025, boss All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the boss developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: boss
 */
package com.hopes.bizz.stop.risk.alarm.service.impl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopes.bizz.stop.common.constant.AlarmDicConstant;
import com.hopes.bizz.stop.risk.alarm.entity.LineAlarmEntity;
import com.hopes.bizz.stop.risk.alarm.entity.LineAlarmHandleRecordEntity;
import com.hopes.bizz.stop.risk.alarm.mapper.LineAlarmHandleRecordMapper;
import com.hopes.bizz.stop.risk.alarm.service.LineAlarmHandleRecordService;
import com.hopes.bizz.stop.risk.alarm.service.LineAlarmOverproofService;
import com.hopes.bizz.stop.risk.alarm.support.AlarmServiceFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 报警处理记录
 *
 * @author pig
 * @date 2024-02-22 16:23:32
 */
@Service
@RequiredArgsConstructor
public class LineAlarmHandleRecordServiceImpl extends ServiceImpl<LineAlarmHandleRecordMapper, LineAlarmHandleRecordEntity> implements LineAlarmHandleRecordService {

    private final LineAlarmOverproofService lineAlarmOverproofService;

    @Override
    public void saveAndUpdateAlarm(LineAlarmHandleRecordEntity lineAlarmHandleRecord) {
        String moduleCode = lineAlarmHandleRecord.getModuleCode();
        //报警信息id
        Long alarmId = lineAlarmHandleRecord.getModuleId();
        IService service = AlarmServiceFactory.map.get(moduleCode);
        LineAlarmEntity lineAlarmEntity = (LineAlarmEntity)service.getById(alarmId);
        lineAlarmEntity.setHandleResult(lineAlarmHandleRecord.getHandleResult());
        lineAlarmEntity.setHandleStatus(AlarmDicConstant.ALARM_HANDLE_PROCESSED);
        lineAlarmEntity.setHandleContent(lineAlarmHandleRecord.getRemarks());
        service.updateById(lineAlarmEntity);
        save(lineAlarmHandleRecord);
    }
}
